//
//  MTTostaView.swift
//  MT
//
//  Created by zhang qiang on 2018/12/9.
//  Copyright © 2019年 张强. All rights reserved.
//

import UIKit

public enum ToastIcon: String {
    case warning = "addCar_icon_fail"
    case success = "collect_icon_success"
}

public class MTTostaView: UIView {
    
    
    let bgv = UIView().then {
        $0.backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
        $0.layer.cornerRadius = 10
    }
    
    let iconV = UIImageView().then {
        $0.sizeToFit()
    }
    
    let tipLbl = UILabel().then {
        $0.textColor = UIColor(hex: 0xFFFFFF)
        $0.font = PingFangSCLightFont(15)
        $0.textAlignment = .center
        $0.numberOfLines = 0
    }
    
    public init(_ frame: CGRect = UIScreen.main.bounds, image: ToastIcon, text: String, duration: TimeInterval = 3, width: CGFloat = 180) {
        super.init(frame: frame)
        
        iconV.image = UIImage.imagePath(named: image.rawValue, bundle: Bundle.MTCategroy)!
        tipLbl.text = text
        
        addSubview(bgv)
        bgv.addSubview(iconV)
        bgv.addSubview(tipLbl)
        
        bgv.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(width)
            //make.height.equalTo(size.height)
        }
        
        iconV.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            //make.centerY.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(15)
        }
        
        tipLbl.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(iconV.snp.bottom).offset(15)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.bottom.equalToSuperview().offset(-15)
        }
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
